/*******************************************************************************************
 *  ActionRef.c
 *
 *  Creating and managing Fire object strucutres.
 *
 *******************************************************************************************/







/*******************************************************************************************
 *  INCLUDES :
 *******************************************************************************************/

/* System and library related : */
#include <stdlib.h>
#include <string.h>

/* Project related : */
#include "ActionRef.h"







/*******************************************************************************************
 *  FUNCTIONS :
 *******************************************************************************************/

/*******************************************************************************************
 *  NEWACTIONREF : Creates an empty ActionRef object structure.
 *******************************************************************************************/
ActionRef *newActionRef(void) {
	ActionRef *a;

	/* Creating the container structure : */
	a = (ActionRef *)malloc(sizeof(ActionRef));


	/* Setting the object's type : */
	a->otype = actionRef;


	/* For now, the ActionRef has no parameters, so : */
	a->paramsNum = 0;
	

	/* Returning the still empty structure : */
	return a;

}




/*******************************************************************************************
 *  FREEACTIONREF : destroys an ActionRef object structure and all the objects it stores.
 *******************************************************************************************/
void freeActionRef(ActionRef *a) {

	int i;							/* All purpose counter.                 */

	free(a->label);					/* Free the label char chain.           */

	for(i=0; i<a->paramsNum; i++)
		free(a->params[i]);			/* Free all the parameters char chains. */

	free(a);						/* Free the object itself.              */

}



/*******************************************************************************************
 *  SETACTIONREFLABEL : sets an action label.
 *******************************************************************************************/
void setActionRefLabel(ActionRef *a, char *l) {

	if(l != NULL) {
		a->label = malloc(MAX_LABEL_LENGTH);
		strcpy(a->label, l);
	}
	else
		a->label = NULL;

}



/*******************************************************************************************
 *  PUSHACTIONREFPARAM : pushes a new parameter on the actionRef's parameters list :
 *******************************************************************************************/
void pushActionRefParam(ActionRef *a, char *p) {
	strcpy(a->params[a->paramsNum], p);
	a->paramsNum++;
}
